/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package traditional_server;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 *
 * @author Teva
 */
public class Traditional_Server 
{
     
    

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException
    {
       
     ServerSocket ss;
     Socket connection = null;
     DataInputStream input;
     
       //1. creating a server socket
	ss = new ServerSocket(5000, 10); 
        
        //2. Wait for connection
	System.out.println("Waiting for connection");        
        connection = ss.accept();
        System.out.println("Connection received from " + connection.getInetAddress().getHostName());
        //3. get Input and Output streams
	input = new DataInputStream(connection.getInputStream());
        
        //4. print the received data
        byte[] byteArray = new byte[4096];    
           while(true) 
           {
                int nread = input.read(byteArray , 0, 4096);

                if (0==nread) break;           
            }
       
	/*
         //Printing the received data on screen
          Scanner socketReader = new Scanner(connection.getInputStream());

           while(socketReader.hasNext())
             {
                  //Reading the content of the socket input stream.
                 System.out.println(socketReader.nextLine());             

             }
          */
        
      
       connection.close();
           
    }
   
     
  
}
